<html>
<head><meta charset="utf-8"><title>abort emits 2 instructions · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html">abort emits 2 instructions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="175520735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175520735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175520735">(Sep 12 2019 at 11:45)</a>:</h4>
<p>Just to triple check, why is <code>core::intrinsics::abort</code> emitting 2x <code>ud2</code>s? <a href="https://gcc.godbolt.org/z/FoqYRc" target="_blank" title="https://gcc.godbolt.org/z/FoqYRc">https://gcc.godbolt.org/z/FoqYRc</a><br>
I can't seem to trigger the same behavior using llc, so the only reason I can imagine is that this is required for alignment purposes or similar.</p>



<a name="175522688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175522688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175522688">(Sep 12 2019 at 12:15)</a>:</h4>
<p><code>call @llvm.trap</code> -&gt; ud2, and rustc sets a TargetMachine option to "trap on unreachable" so the <code>unreachable</code> also becomes an ud2. Manually feeding IR to llc will be missing the latter.</p>



<a name="175526011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526011">(Sep 12 2019 at 13:00)</a>:</h4>
<p>So do we have a bug in the implementation of <code>core::intrinsics::abort</code>, <code>core::arch::x86_64::ud2</code>, etc. ?</p>



<a name="175526046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526046">(Sep 12 2019 at 13:01)</a>:</h4>
<p>IIUC, we could use <code>core::hint::unreachable_unchecked()</code> to only emit a single <code>unreachable</code>, and therefore a single <code>ud2</code> ?</p>



<a name="175526183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526183">(Sep 12 2019 at 13:02)</a>:</h4>
<p>So that works: <a href="https://gcc.godbolt.org/z/jrhehx" target="_blank" title="https://gcc.godbolt.org/z/jrhehx">https://gcc.godbolt.org/z/jrhehx</a></p>



<a name="175526236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526236">(Sep 12 2019 at 13:03)</a>:</h4>
<p>No</p>



<a name="175526304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526304">(Sep 12 2019 at 13:03)</a>:</h4>
<p>While we're mitigating harm by asking the <em>backend</em> to emit ud2 rather than just letting control flow fall off the end of the function, the entire optimization pipeline will still exploit that <code>unreachable</code> is, well, unreachable.</p>



<a name="175526399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526399">(Sep 12 2019 at 13:04)</a>:</h4>
<p>Ah, makes sense</p>



<a name="175526416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526416">(Sep 12 2019 at 13:04)</a>:</h4>
<p>Also I am not even sure if every backend does this.</p>



<a name="175526425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526425">(Sep 12 2019 at 13:04)</a>:</h4>
<p>Then I maybe should open an LLVM bug for an x86 backend optimization ?</p>



<a name="175526432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526432">(Sep 12 2019 at 13:04)</a>:</h4>
<p>multiple ud2s can be coalesced</p>



<a name="175526442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526442">(Sep 12 2019 at 13:04)</a>:</h4>
<p>but the x86 backend doesn't do that</p>



<a name="175526447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526447">(Sep 12 2019 at 13:05)</a>:</h4>
<p>I mean, feel free, but this is literal peanuts</p>



<a name="175526492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/abort%20emits%202%20instructions/near/175526492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/abort.20emits.202.20instructions.html#175526492">(Sep 12 2019 at 13:05)</a>:</h4>
<p>Not only are the ud2s a minuscle fraction of instructions emitted, they're also just two bytes each</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>